load("//bzl:cpp_library.bzl", "cpp_library")

package(default_visibility = ["//visibility:public"])

cpp_library(
    name = "async_trace",
    srcs = ["AsyncTrace.cpp"],
    hdrs = ["AsyncTrace.h"],
    deps = [
        "//folly:optional",
        "//folly:portability",
    ],
)

cpp_library(
    name = "atomic_hash_utils",
    hdrs = ["AtomicHashUtils.h"],
    deps = [
        "//folly/portability:asm",
    ],
)

cpp_library(
    name = "atomic_unordered_map_utils",
    hdrs = ["AtomicUnorderedMapUtils.h"],
    deps = [
        "//folly:exception",
        "//folly/portability:sys_mman",
        "//folly/portability:unistd",
    ],
)

cpp_library(
    name = "discriminated_ptr_detail",
    hdrs = ["DiscriminatedPtrDetail.h"],
    deps = [
        "//folly/functional:invoke",
    ],
)

cpp_library(
    name = "file_util_detail",
    srcs = ["FileUtilDetail.cpp"],
    hdrs = ["FileUtilDetail.h"],
    deps = [
        "//folly/portability:config",
        "//folly/portability:sys_types",
    ],
)

cpp_library(
    name = "file_util_vector_detail",
    hdrs = ["FileUtilVectorDetail.h"],
    deps = [
        ":file_util_detail",
        "//folly/portability:sys_uio",
        "//folly/portability:unistd",
    ],
)

cpp_library(
    name = "fingerprint_polynomial",
    hdrs = ["FingerprintPolynomial.h"],
)

cpp_library(
    name = "futex",
    srcs = ["Futex.cpp"],
    hdrs = [
        "Futex.h",
    ],
    textual_hdrs = [
        "Futex-inl.h",
    ],
    deps = [
        "//folly:scope_guard",
        "//folly/hash",
        "//folly/portability:sys_syscall",
        "//folly/portability:unistd",
        "//folly/synchronization:parking_lot",
    ],
)

cpp_library(
    name = "group_varint_detail",
    hdrs = ["GroupVarintDetail.h"],
)

cpp_library(
    name = "ip_address",
    srcs = ["IPAddress.cpp"],
    hdrs = ["IPAddress.h"],
    deps = [
        "//folly/portability:fmt_compile",
        "//folly/portability:sockets",
    ],
)

cpp_library(
    name = "ip_address_source",
    hdrs = ["IPAddressSource.h"],
    deps = [
        ":ip_address",
        "@fmt",
        "@glog",
    ],
)

cpp_library(
    name = "iterators",
    hdrs = ["Iterators.h"],
)

cpp_library(
    name = "memory_idler",
    srcs = ["MemoryIdler.cpp"],
    hdrs = ["MemoryIdler.h"],
    deps = [
        ":futex",
        "//folly:glog",
        "//folly:portability",
        "//folly:scope_guard",
        "//folly/concurrency:cache_locality",
        "//folly/hash",
        "//folly/memory:mallctl_helper",
        "//folly/memory:malloc",
        "//folly/portability:gflags",
        "//folly/portability:pthread",
        "//folly/portability:sys_mman",
        "//folly/portability:unistd",
        "//folly/synchronization:atomic_struct",
        "//folly/system:pid",
        "//folly/system:thread_id",
    ],
)

cpp_library(
    name = "perf_scoped",
    srcs = ["PerfScoped.cpp"],
    hdrs = ["PerfScoped.h"],
    deps = [
        "//folly:conv",
        "//folly/system:pid",
        "//folly/testing:test_util",
    ] + select({
        # folly subprocess is not supported on windows
        "@platforms//os:linux": ["//folly:subprocess"],
        "//conditions:default": [],
    }),
)

cpp_library(
    name = "mpmc_pipeline_detail",
    hdrs = ["MPMCPipelineDetail.h"],
    deps = [
        "//folly:mpmc_queue",
    ],
)

cpp_library(
    name = "poly_detail",
    hdrs = ["PolyDetail.h"],
    deps = [
        ":typelist",
        "//folly:poly_exception",
        "//folly:portability",
        "//folly:traits",
        "//folly:utility",
        "//folly/functional:invoke",
        "//folly/lang:exception",
        "//folly/lang:static_const",
    ],
)

cpp_library(
    name = "range_common",
    srcs = ["RangeCommon.cpp"],
    hdrs = ["RangeCommon.h"],
    deps = [
        "//folly:likely",
        "//folly/container:sparse_byte_set",
    ],
)

cpp_library(
    name = "range_simd",
    srcs = ["RangeSimd.cpp"],
    hdrs = ["RangeSimd.h"],
    deps = [
        ":range_common",
        ":range_sse42",
        "//folly:portability",
        "//folly/external/nvidia/detail:range_sve2",
    ],
)

cpp_library(
    name = "range_sse42",
    srcs = ["RangeSse42.cpp"],
    hdrs = ["RangeSse42.h"],
    deps = [
        ":range_common",
        ":sse",
        "//folly:likely",
        "//folly:portability",
    ],
)

cpp_library(
    name = "singleton",
    hdrs = ["Singleton.h"],
    deps = [
        "//folly:traits",
    ],
)

cpp_library(
    name = "slow_fingerprint",
    hdrs = ["SlowFingerprint.h"],
    deps = [
        ":fingerprint_polynomial",
        "//folly:fingerprint",
        "//folly:range",
    ],
)

cpp_library(
    name = "sse",
    srcs = ["Sse.cpp"],
    hdrs = ["Sse.h"],
    deps = [
        "//folly:portability",
    ],
)

cpp_library(
    name = "simple_simd_string_utils",
    srcs = ["SimpleSimdStringUtils.cpp"],
    hdrs = [
        "SimpleSimdStringUtils.h",
        "SimpleSimdStringUtilsImpl.h",
    ],
    deps = [
        "//folly:range",
        "//folly/algorithm/simd/detail:simd_any_of",
        "//folly/algorithm/simd/detail:simd_platform",
    ],
)

cpp_library(
    name = "split_string_simd",
    srcs = ["SplitStringSimd.cpp"],
    hdrs = [
        "SplitStringSimd.h",
        "SplitStringSimdImpl.h",
    ],
    deps = [
        "//folly:fbstring",
        "//folly:fbvector",
        "//folly:portability",
        "//folly:range",
        "//folly:small_vector",
        "//folly/algorithm/simd:ignore",
        "//folly/algorithm/simd:movemask",
        "//folly/algorithm/simd/detail:simd_for_each",
        "//folly/algorithm/simd/detail:simd_platform",
        "//folly/lang:bits",
    ],
)

cpp_library(
    name = "socket_fast_open",
    srcs = ["SocketFastOpen.cpp"],
    hdrs = ["SocketFastOpen.h"],
    deps = [
        "//folly/net:network_socket",
        "//folly/portability:sockets",
    ],
)

cpp_library(
    name = "static_singleton_manager",
    srcs = ["StaticSingletonManager.cpp"],
    hdrs = ["StaticSingletonManager.h"],
    deps = [
        ":singleton",
        "//folly:c_portability",
        "//folly:indestructible",
        "//folly:likely",
        "//folly:utility",
        "//folly/lang:thunk",
        "//folly/lang:type_info",
        "//folly/memory:reentrant_allocator",
    ],
)

cpp_library(
    name = "thread_local_detail",
    srcs = ["ThreadLocalDetail.cpp"],
    hdrs = ["ThreadLocalDetail.h"],
    deps = [
        ":static_singleton_manager",
        ":thread_local_globals",
        ":unique_instance",
        "//folly:constexpr_math",
        "//folly:exception",
        "//folly:function",
        "//folly:map_util",
        "//folly:portability",
        "//folly:scope_guard",
        "//folly:shared_mutex",
        "//folly:synchronized",
        "//folly:utility",
        "//folly/concurrency/container:atomic_grow_array",
        "//folly/container:foreach",
        "//folly/lang:exception",
        "//folly/lang:hint",
        "//folly/memory:malloc",
        "//folly/memory:sanitize_leak",
        "//folly/portability:pthread",
        "//folly/synchronization:call_once",
        "//folly/synchronization:micro_spin_lock",
        "//folly/synchronization:relaxed_atomic",
        "//folly/system:at_fork",
        "//folly/system:thread_id",
        "@glog",
    ],
)

cpp_library(
    name = "thread_local_globals",
    srcs = ["thread_local_globals.cpp"],
    hdrs = ["thread_local_globals.h"],
    deps = [
        ":static_singleton_manager",
        "//folly/lang:exception",
        "//folly/portability:pthread",
    ],
)

cpp_library(
    name = "turn_sequencer",
    hdrs = ["TurnSequencer.h"],
    deps = [
        ":futex",
        "//folly:portability",
        "//folly/chrono:hardware",
        "//folly/portability:asm",
        "//folly/portability:unistd",
        "@glog",
    ],
)

cpp_library(
    name = "typelist",
    hdrs = ["TypeList.h"],
    deps = [
        "//folly:traits",
        "//folly:utility",
    ],
)

cpp_library(
    name = "unique_instance",
    srcs = ["UniqueInstance.cpp"],
    hdrs = ["UniqueInstance.h"],
    deps = [
        ":static_singleton_manager",
        "//folly:cpp_attributes",
        "//folly:demangle",
        "//folly/lang:exception",
    ],
)

cpp_library(
    name = "traponavx512",
    srcs = ["TrapOnAvx512.cpp"],
    hdrs = ["TrapOnAvx512.h"],
    copts = select({
        "@platforms//cpu:x86_64": [
            "-msse4.2",
            "-mavx512f",
            "-mavx512vl",
        ],
        "//conditions:default": [],
    }),
    deps = [
        "//folly:portability",
    ],
)
